package ebook.datastructure.typed.chapter10;

import lombok.Data;

/**
 * description: <br>
 * createTime: 2020/8/2817:19 <br>
 *
 * @author zzh
 */
//TODO 待完成
public class Tree234 <T extends Comparable> {
    Tree234Node<T> root;

    public Tree234() {}

    public void addValue(T value) {
        if(root == null) {
            root = new Tree234Node<>();
            root.setValueA(value);
        } else {
            addValue(value, root);
        }
    }


    private void addValue(T value, Tree234Node<T> node) {
        // 当前节点为叶节点，如果不满，则直接插入数据项，如果满了，则要分裂父节点
        if(node.isLeafNode()) {
            // 如果
            if(!node.isNodeFull()) {
               node.insertValue(value);
            } else {
                //TODO 叶子节点已满
            }
        }
    }


    @Data
    public class Tree234Node <T extends Comparable> {
        T valueA;
        T valueB;
        T valueC;
        Tree234Node<T> parent;
        Tree234Node<T> nodeA;
        Tree234Node<T> nodeB;
        Tree234Node<T> nodeC;
        Tree234Node<T> nodeD;

        public boolean isLeafNode() {
            return nodeA == null;
        }

        public boolean isNodeFull() {
            return valueC != null;
        }

        public void insertValue(T value) {
            if(valueA.compareTo(value) > 0) {
                valueC = valueB;
                valueB = valueA;
                valueA = value;
            } else if(valueB == null) {
                valueB = value;
            } else if(valueB.compareTo(value) > 0) {
                valueC = valueB;
                valueB = value;
            }
        }
    }
}
